package com.lcj.demo.web;

import com.lcj.demo.domain.Department;
import com.lcj.demo.service.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(value = "部门", description = "部门相关操作Api")
@RestController
@RequestMapping("/api")
public class DepartmentController {
    private final DepartmentService departmentService;

    public DepartmentController(DepartmentService departmentService) {
        this.departmentService = departmentService;
    }

    @ApiOperation(value="获取部门列表")
    @GetMapping("/departments")
    public List<Department> findAllNopage() {
        return departmentService.findAll();
    }

    @ApiOperation(value="创建部门", notes="根据Department对象创建部门")
    @ApiImplicitParam(name = "Department", value = "详细实体", required = true, dataType = "Department")
    @PostMapping("/department")
    public Department create(@RequestBody Department department) {
        return departmentService.saveOrUpdate(department);
    }

    @ApiOperation(value="更新部门信息", notes="根据Department对象更新部门信息")
    @ApiImplicitParam(name = "Department", value = "详细实体", required = true, dataType = "Department")
    @PutMapping("/department")
    public Department update(@RequestBody Department department) {
        return departmentService.saveOrUpdate(department);
    }

    @ApiOperation(value="根据id删除部门信息", notes="根据id删除部门信息")
    @ApiImplicitParam(name = "ID", value = "部门ID", required = true, dataType = "Long")
    @DeleteMapping("/department/{id}")
    public void delete(@PathVariable("id") Long id) {
        departmentService.delete(id);
    }

}
